﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace SensorDetection
{
    class TestObserver2 : IObserver
    {
        #region IObserver Members
        public void Update(string sender, object msg)
        {
            if (msg == null)
            {
                Console.WriteLine("The {0} detected nothing", sender);
            }
            else
            {
                if (msg.GetType().ToString().StartsWith("System.Collections.Generic.List"))
                //if(msg.GetType()==typeof(System.Collections.Generic.List'1[SHDocVw.InternetExplorer]))
                {
                    List<SHDocVw.InternetExplorer> ieList = (List<SHDocVw.InternetExplorer>)msg;
                    foreach (SHDocVw.InternetExplorer ie in ieList)
                    {
                        Console.WriteLine("Site: {0}",ie.LocationURL);
                    }
                    Console.WriteLine("{0} observed by TestObserver2", sender);
                }
                else if (msg.GetType()==typeof(System.Single))//float
                {
                    Console.WriteLine("{0} sends {1}",sender,(float)msg);
                }
                else if (msg.GetType().ToString().EndsWith("[]"))
                {
                    if (msg.GetType()==typeof(System.Diagnostics.Process[]))
                    //if (msg.GetType().ToString().StartsWith("System.Diagnostics.Process"))//if a process event
                    {
                        Process[] proc = (Process[])msg;
                        foreach (Process p in proc)
                            Console.WriteLine(p.ProcessName);
                    }
                }
                //if msg is a single string
                else if (Object.ReferenceEquals("test".GetType(), msg.GetType()))
                    Console.WriteLine("{0} sends {1} observed by TestObserver2", sender, (string)msg);
            }
        }
        #endregion
    }
}